<?php


class CommentAction extends BaseAction {
	public function add(){
		$pId = isset($_POST['pId']) ? trim($_POST['pId']) : 0;
		$name = isset($_POST['name']) ? trim($_POST['name']) : '';
		$email = isset($_POST['email']) ? trim($_POST['email']) : '';
		$web = isset($_POST['web']) ? trim($_POST['web']) : '';
		$content = isset($_POST['content']) ? trim($_POST['content']) : '';
		if(0 == $pId || '' == $name || '' == $email || '' == $content || strlen($name) > 32 || strlen($email) > 32 || strlen($web) > 32 || strlen($content) > 255){
			$result['info'] = 'access denied！';
			$result['status'] = '500';
			$this->ajaxReturn($result);
		}

		$data = array(
			'level' => '1',
			'nickname' => $name,
			'email' => $email,
			'web_site' => $web,
			'level' => 0
			);
		$res = M('User')->data($data)->add();	
		unset($data);
		if($res){
			$data['u_id'] = $res;
			$data['p_id'] = $pId;
			$data['content'] = $content;
			$data['add_time'] = time();
			$res = M('Comment')->data($data)->add();
			if($res){
				$result['info'] = '成功！';
				$result['status'] = '200';
				$this->ajaxReturn($result);
			}
		}else{
			$result['info'] = '评论失败！';
			$result['status'] = '500';
			$this->ajaxReturn($result);
		}	

		
	}
}